<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
	<title>角色管理</title>

	<!-- 使用bootbox的增强式alert/confirm/prompt -->	
	<script src="${ctx}/static/metronic/assets/plugins/bootbox/bootbox.min.js" type="text/javascript"></script>
	<script>
	//http://bootboxjs.com/
	function publish(id){
		bootbox.confirm("确实发布这条角色？", function(result) {
            if(result){
				location.href = "${ctx}/role/publish/" + id;
            }
        }); 
	}
	function remove(id){
		bootbox.confirm("确实删除这条角色？", function(result) {
            if(result){
				location.href = "${ctx}/role/delete/" + id;
            }
        }); 
	}
	</script>
	
	<!-- select2组合框 -->
	<link rel="stylesheet" type="text/css" href="${ctx}/static/metronic/assets/plugins/select2/select2_metro.css"/>
	<script type="text/javascript" src="${ctx}/static/metronic/assets/plugins/select2/select2.min.js"></script>
	
</head>

<body>
<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content">
			<!-- 提示信息 -->
			<c:if test="${not empty message}">
				<div id="message" class="alert alert-${not empty messageType ? messageType : 'success'}"><button data-dismiss="alert" class="close">×</button>${message}</div>
			</c:if>
			
			<!-- 查询表单 -->
			<div class="portlet-body">
			<form class="form-inline" action="#">
				<div class="form-group">
					<label class="sr-only" for="search_name">名称</label>
					<input type="text" id="search_name" name="search_name" class="form-control" placeholder="按名称查询" value="${param.search_name}"/>
				</div>
				<div class="form-group">
					<label class="sr-only" for="search_isenabled">状态</label>
					<select name="search_isenabled" id="search_industry" class="form-control input-small select2me" data-placeholder="按发布状态查询">
						<option value="">全部状态</option>
						<option value="0" ${(not empty param.search_isenabled) && param.search_isenabled==0 ? "selected=\"selected\"" : ""}>草稿</option>
						<option value="1" ${param.search_isenabled==1 ? "selected=\"selected\"" : ""}>已发布</option>
					</select>
				</div>
				<button type="submit" class="btn btn-default">查询</button>
			</form>
			</div>
			
			<hr>
			
			<div class="row list-buttons">
				<div class="col-md-12">
					<a href="${ctx}/role/create" class="btn green">新建角色</a>
				</div>
			</div>
			
			<!-- 数据表格 -->
			<!-- BEGIN PAGE HEADER-->
			<div class="row">
				<div class="col-md-12">
					<!-- BEGIN SAMPLE TABLE PORTLET-->
					<div class="portlet box green">
						<div class="portlet-title">
							<div class="caption">
								<i class="fa fa-cogs"></i>角色列表
							</div>
						</div>
						<div class="portlet-body">
							<div class="table-responsive">
								<table class="table table-hover">
								<thead>
								<tr>
									<th><tags:sorter field="name"/></th>
									<th><tags:sorter field="isenabled"/></th>
									<th>管理</th>
								</tr>
								</thead>
								<tbody>
								<c:forEach items="${roles.content}" var="role">
								<tr>
									<td>
										<a href="${ctx}/role/update/${role.id}" class="btn default btn-xs purple"><i class="fa fa-edit"> </i> ${role.name}</a>
									</td>
									<td>
										<span class="label label-sm label-${role.isenabled==0?'info':'success'}">
											${role.isenabled==0?'草稿':'已发布'}
										</span>
									</td>
									<td>
										<a href="javascript:remove(${role.id})" class="btn default btn-xs black"><i class="fa fa-trash-o"> </i> 删除</a>
										<c:if test="${role.isenabled==0}">
										<a href="javascript:publish(${role.id})" class="btn default btn-xs blue"><i class="fa fa-share"> </i> 发布</a>
										</c:if>
									</td>
								</tr>
								</c:forEach>
								</tbody>
								</table>
							</div>
						</div>
					</div>
					<!-- END SAMPLE TABLE PORTLET-->
				</div>
			</div>
			
			<tags:pagination page="${roles}" paginationSize="5"/>
	
		</div>
	</div>
</body>
</html>
